package com.dhecp.project.system.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.dhecp.common.config.Global;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.project.system.domain.SysSetting;
import com.dhecp.project.system.mapper.SysSettingMapper;
import com.dhecp.project.system.service.SysSettingService;


/**
 * 系统设置 业务层处理
 * 
 * @author lwl
 */
@Service
public class SysSettingServiceImpl implements SysSettingService{
	
	@Autowired
	private SysSettingMapper settingMapper;

	@Override
	public SysSetting querySetting() {
		SysSetting systemSetting = settingMapper.findSetting();
		systemSetting.setSystemVersion(Global.getVersion()); //读取配置文件中的信息
		systemSetting.setCopyRightYear(Global.getCopyrightYear()); //读取配置文件中的信息
		return systemSetting;
	}

	/**
	 * 系统设置修改
	 * @param settingItems
	 * @return MessageModel
	 * @author lwl
	 */
	@Override
	public AjaxResult updateSetting(Map<String, Object> params) {
		List<SysSetting> settingList = JSON.parseArray(params.get("settingItems").toString(), SysSetting.class);
		if (settingList == null || settingList.size() == 0) {
            return AjaxResult.error("数据包格式有误，请检查！");
        }
		for (SysSetting setting : settingList) {
			setting.setUpdateUser(ShiroUtils.getUserId());
			setting.setUpdateTime(new Date());
			settingMapper.updateSetting(setting);
		}
		return AjaxResult.success("操作成功！");
	}
	/**
	 * 系统Logo修改
	 * @param guid
	 * @return MessageModel
	 * @author kimiloo
	 */
	@Override
	public AjaxResult updateSettingLogo(Map<String, Object> params) {
		settingMapper.updateSettingLogo(params);
		return AjaxResult.success("操作成功！");
	}

	

}
